package com.huike;

import com.huike.clues.service.ISysDeptService;
import com.huike.clues.service.ISysDictDataService;
import com.huike.clues.service.ITbActivityService;
import com.huike.clues.service.ITbClueService;
import com.huike.common.constant.Constants;
import com.huike.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 启动程序
 *
 *
 */
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class})
//@SpringBootApplication
@EnableTransactionManagement
@EnableScheduling
public class HuiKeApplication implements CommandLineRunner {

    @Autowired
    private ITbActivityService activityService;

    @Autowired
    private ITbClueService clueService;

    @Autowired
    private ISysDictDataService sysDictDataService;

    @Autowired
    private RedisCache redisCache;

    public static void main(String[] args){
        SpringApplication.run(HuiKeApplication.class, args);
    }

    @Override
    public void run(String... args)  {
        try{
            redisCache.deleteObject(Constants.CLUE_PHONE_KEY);
            redisCache.deleteObject(Constants.CLUE_ID_KEY);
            //加载所有活动code到缓存
            activityService.loadAllActivityCode1();
            //将当前所有线索的电话加载到缓存中
            clueService.loadAllPhone();
            //将当前所有线索的id加载到缓存中
            clueService.loadAllId();
            //将字典里一一对应的关系加载到缓存中去
            sysDictDataService.loadRelative();
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}

